<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #editor {
            height: 300px;
            border: solid 1px red;
        }

        
    </style>
</head>

<body>

        <div  id="editor" contenteditable="true"></div>
        <div  id="rtfAppend"></div>

  
    <!--
     https://www.cnblogs.com/blfshiye/p/4515520.html  提取图像

    -->


    <script>
        // 监听粘贴功能
        document.getElementById('editor').addEventListener('paste', function (evt) {
            evt.preventDefault();
            const clipItems = evt.clipboardData.items || window.clipboardData.items;

            //const clipItems = evt.dataTransfer.items;

            //console.log( "clipboardData==>",evt.clipboardData)
            //console.log( "====plain==>",evt.clipboardData.getData('text/plain'))
            //console.log( "====html==>",evt.clipboardData.getData('text/html'))
            // let rtf =  evt.clipboardData.getData('Text')
            let rtf= evt.clipboardData.getData('text/rtf')
            if(!rtf){
             rtf = evt.clipboardData.getData('Text')
            }
            console.log("====rtf==>", rtf)

            // document.getElementById('rtfAppend').textContent=rtf
            
            rtfToHtml.fromString(rtf, (err, html) => {
                console.log('-----------------------------------to html')
                console.log(html)
                document.getElementById('editor').innerHTML = html
            })
        })



    </script>
</body>

</html>